﻿
<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>用户维护</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/X-admin/lib/layui/layui.js"></script>
    <link href="~/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/X-admin/js/jquery.min.js"></script>
    <script src="~/X-admin/js/xadmin.js"></script>
    <script src="~/js/framework/sysframework.js"></script>
    <script src="~/js/framework/commonjs.js"></script>
</head>
<body>
    <ul lay-bar="disabled" class="mWebBanner">
        <li class="layui-nav-item" style="float:left;">
            <button id="btn-update" type="button" name="btn_update" onclick="saveData()" class="buttonCss">
                保存数据
            </button>
        </li>
        <li class="layui-nav-item" style="float:left;padding-left:20px">
            <button id="btn-sync" type="button" onclick="closeWin()" class="buttonCss">
                关闭页面
            </button>
        </li>
    </ul>
    <div class="layui-card" style="margin-top:10px">
        <div class="layui-card-body" style="padding-top:3%">
           <form class="layui-form" id="uForm">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="x-red">*</span>生产工序</label>
                        <div class="layui-input-inline">
                            <select name="gxCode" id="gxCode">
                                <option value="">选择工序</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">生产绩效</label>
                        <div class="layui-input-inline">
                            <select name="proFomula" id="proFomula" lay-filter="scjx">
                                <option value="">生产绩效</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <input type="text" id="scfomula" name="scfomula" placeholder="生产绩效计算公式" class="layui-input" style="margin-left:5%;width:95%" readonly />
                            <input type="hidden" id="id" name="id" >
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">报工绩效</label>
                        <div class="layui-input-inline">
                            <select name="reportFomula" id="reportFomula" lay-filter="bgjx">
                                <option value="">生产绩效</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                    <input type="text" id="bgfomula" name="bgfomula" placeholder="报工绩效计算公式" class="layui-input" style="margin-left:5%;width:95%" readonly />

                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label for="L_email" class="layui-form-label">
                           备注说明
                        </label>
                        <div class="layui-input-block">
                            <input type="text" id="memo" name="memo" autocomplete="off" class="layui-input">
                        </div>

                    </div>


                </form>

        </div>
        
    </div>
</body>
</html>
<script>
    var dataId = "";
    $(function () {

        CommonData("Gx", "gxCode", "");
        loadFomula("proFomula,reportFomula");
        dataId = getUrlVariable("dataId");
        if (dataId != "0") {
            $("input[ name='id']").val(dataId);
            loadDataById(dataId); //加载数据
        }
        layui.use('form', function () {
            var form = layui.form;
            form.on('select(scjx)', function (data) {
                showGongShi(data.value, "scfomula");
            });
            form.on('select(bgjx)', function (data) {
                showGongShi(data.value, "bgfomula");
            });
        });

    })
    function showGongShi(dataId,controlName){
        var info="";
        for (var i = 0; i < fomulaInfo.length; i++) {
            if (fomulaInfo[i]["id"] == dataId) {
               info="计算公式："+fomulaInfo[i]["formula"] + "；  关联数据： " + fomulaInfo[i]["relationName"];
                break;
            }
        }
         $("input[ name='" + controlName + "']").val(info);
    }

    /**
    数据保存
    **/
    function saveData() {
        $.ajax({
            url: "../Wage/SavaGongXuWage",
            data: { data: JSON.stringify(FormToJson("uForm")) },
            dataType: "json",
            type: "POST",
            success: function (rsl) {
                if (rsl.result) {
                    layer.alert("保存成功", { icon: 6 }, function () {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                    });
                } else {
                    layer.msg(rsl.message);
                }
            }
        });
    }

    //加载用户数据信息
    function loadDataById(dataId) {
        $.ajax({
            url: "../Wage/loadGXFormulaByID",
            type: "post",
            data: { dataId: dataId },
            success: function (rsl) {
                if (rsl.result) {
                    $.each(rsl.data[0], function (name, value) {
                        if (name != "gxCode" && name != "proFomula" && name != "reportFomula") {
                            $("input[ name='" + name + "']").val(value);
                        } else if (name == "proFomula" || name == "gxCode" || name == "reportFomula") {
                        $("#" + name + " option[value='" + value + "'] ").attr("selected", true);
                           if(name=="proFomula"){
                                showGongShi(value, "scfomula");
                            } else if (name == "reportFomula") {
                                showGongShi(value, "bgfomula");
                           }
                        layui.use('form', function () {
                                var form = layui.form;
                                form.render();
                            });
                        }

                    });

                }

            }
        });

    }
    let fomulaInfo;
    function loadFomula(controlId) {
        $.ajax({
            url: "../Wage/getFomulaInfo",
            dataType: "json",
            type: "POST",
            async: false,
            success: function (rsl) {
                if (rsl.result) {
                    fomulaInfo=rsl.data;
                    var arr = controlId.split(',');
                    for(var y=0;y<arr.length;y++){
                        $("select[name='" + arr[y] + "'] option:gt(0)").remove();   //先清空除第一个以外全部的option  ，再重新添加
                        for (var i = 0; i < fomulaInfo.length; i++) {
                            if (fomulaInfo[i]["id"] != "") {
                                $("#" + arr[y]).append("<option value=\"" + fomulaInfo[i]["id"] + "\" >" + fomulaInfo[i]["gsName"] + "</option>");
                            }
                        }
                    }
                 
                    layui.use('form', function () {
                        var form = layui.form;
                        form.render();
                    });
                }
            }
        });
    }

</script>

